package routers

import (
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	"github.com/swaggo/gin-swagger"
	_ "z-blog/docs"
	"z-blog/middleware"
	"z-blog/middleware/jwt"
	"z-blog/routers/api"
	"z-blog/setting"
)

func InitRouter() *gin.Engine {
	r := gin.New()

	r.Use(middleware.Cors())
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	gin.SetMode(setting.RunMode)

	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	r.GET("/get_auth", api.GetAuth)

	userApi := r.Group("/auth")
	userApi.Use(jwt.JWT())
	{
		userApi.GET("/get_info", api.GetAuthInfo)
	}

	tagApi := r.Group("/tag")
	tagApi.Use(jwt.JWT())
	{
		tagApi.GET("/get_all", api.GetTagAll)
		tagApi.GET("/add", api.AddTag)
		tagApi.GET("/del", api.DelTag)
	}

	articleApi := r.Group("/article")
	articleApi.Use(jwt.JWT())
	{
		articleApi.GET("/get_by_tag", api.GetArticleByTag)
		articleApi.GET("/get_by_id", api.GetArticleById)
		articleApi.GET("/get_by_tag_basic", api.GetArticleByTagBasic)
		articleApi.POST("/add", api.AddArticle)
		articleApi.GET("/del", api.DelArticle)
		articleApi.GET("/thumbs_up", api.ThumbsUp)
	}

	gameApi := r.Group("/game")
	{
		gameApi.GET("/set_gomoku_map", api.SetChess)
		gameApi.GET("/restart", api.RestartGame)
		gameApi.GET("/get_gomoku_map", api.GetMapData)
	}

	commentApi := r.Group("/comment")
	commentApi.Use(jwt.JWT())
	{
		commentApi.GET("/get_comment_by_article", api.GetCommentByArticle)
		commentApi.GET("/add", api.AddComment)
		commentApi.GET("/del", api.DelComment)
	}

	return r
}
